package data;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Allows the program clock to call update on each iteration
 * @author lax116
 *
 */
public abstract class ClockInterface {
	public abstract void update(Calendar c);;
	
	public static String getTodayDate(String dateStyle){
		String dateNow = "";
		Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat(dateStyle);
		dateNow = dateFormat.format(calendar.getTime());
		return dateNow;
	}
	public static Calendar StrToCalendar(String dateStr) throws ParseException{
		SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yy");
		Date convertedDate = dateFormat.parse(dateStr);
		Calendar cal=Calendar.getInstance();
		cal.setTime(convertedDate);
		return cal; 
	}
	public static String DateToStr(Date dateT){
		String dateS;
		SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yy");
		dateS = dateFormat.format(dateT);
		return dateS;
	}
	public static boolean aAfterB(Calendar a, Calendar b, int days){
		b.add(Calendar.DAY_OF_YEAR, days);
		if(a.after(b)  || a.equals(b)){
			b.add(Calendar.DAY_OF_YEAR, -days);
			return true;
		}else{
			b.add(Calendar.DAY_OF_YEAR, -days);
			return false;
		}
	}
	/**
	 * Checks if one calendar is before another by a certain number of days
	 * @param b
	 * @param a
	 * @param days
	 * @return
	 */
	public static boolean aBeforeB(Calendar a, Calendar b, int days){
		b.add(Calendar.DAY_OF_YEAR, -days);
		if(a.after(b)){
			b.add(Calendar.DAY_OF_YEAR, days);
			return true;
		}else{
			b.add(Calendar.DAY_OF_YEAR, days);
			return false;
		}
	}
}
